package com.yunhai.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yunhai.common.dto.GlobalException;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.utils.ObjectUtil;
import com.yunhai.common.utils.ReflectionCopy;
import com.yunhai.device.mapper.DmsPullTeaDataDictMapper;
import com.yunhai.device.service.DmsPullTeaDataDictService;
import com.yunhai.model.entity.dms.DmsPullTeaDataDictEntity;
import com.yunhai.model.vo.dms.DmsPullTeaDataDictQuery;
import com.yunhai.model.vo.dms.DmsPullTeaDataDictVo;
import org.apache.commons.beanutils.PropertyUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DmsPullTeaDataDictServiceImpl implements DmsPullTeaDataDictService {

    @Resource
    private DmsPullTeaDataDictMapper dmsPullTeaDataDictMapper;

    /**
     * 获取 DmsPullTeaDataDict 分页列表
     */
    @Transactional
    public IPage getDmsPullTeaDataDictPagination(PaginationVo paginationVo, DmsPullTeaDataDictQuery dmsPullTeaDataDictQuery ) throws Exception {

        IPage page = new Page( paginationVo.getPageIndex(), paginationVo.getPageSize() );
        LambdaQueryWrapper<DmsPullTeaDataDictEntity> lqs = new LambdaQueryWrapper();
        dmsPullTeaDataDictMapper.selectPage(page, lqs);

        List<DmsPullTeaDataDictEntity> record = page.getRecords();
        if( !ObjectUtil.isNotEmptyList(record)){
            return page;
        }
        return null;
    }


    /**
     * 获取 DmsPullTeaDataDict 所有数据
     *
    */
    @Transactional
    public List<DmsPullTeaDataDictEntity> getDmsPullTeaDataDictAllList( DmsPullTeaDataDictQuery dmsPullTeaDataDictQuery ) throws Exception {

        LambdaQueryWrapper<DmsPullTeaDataDictEntity> lqs = new LambdaQueryWrapper();
        List<DmsPullTeaDataDictEntity> list = dmsPullTeaDataDictMapper.selectList(lqs);
        return list;
    }


    /**
     * 获取 DmsPullTeaDataDict 详情
    */
    @Transactional
    public DmsPullTeaDataDictEntity getDmsPullTeaDataDictDetail( Long id) throws Exception {

        DmsPullTeaDataDictEntity dmsPullTeaDataDict = dmsPullTeaDataDictMapper.selectById(id);
        return dmsPullTeaDataDict;
    }


    /**
     * 新增 DmsPullTeaDataDict
     * */
    @Transactional
    public void addDmsPullTeaDataDict(DmsPullTeaDataDictVo dmsPullTeaDataDictVo) throws Exception {

        DmsPullTeaDataDictEntity dmsPullTeaDataDict = new DmsPullTeaDataDictEntity();
        ReflectionCopy.copyProperties( dmsPullTeaDataDict, dmsPullTeaDataDictVo );
        dmsPullTeaDataDictMapper.insert(dmsPullTeaDataDict);
        return;
    }


    /**
     * 更新 DmsPullTeaDataDict
     * */
    @Transactional
    public void updateDmsPullTeaDataDict( DmsPullTeaDataDictVo dmsPullTeaDataDictVo) throws Exception {

        if( dmsPullTeaDataDictVo.getId() == null ){
            throw GlobalException.gen(10021, "id不存在");
        }
        DmsPullTeaDataDictEntity dmsPullTeaDataDict = new DmsPullTeaDataDictEntity();
        ReflectionCopy.copyProperties( dmsPullTeaDataDict, dmsPullTeaDataDictVo );
        dmsPullTeaDataDictMapper.updateById(dmsPullTeaDataDict);
        return;
    }

    /**
     * 删除 DmsPullTeaDataDict
     * */
    @Transactional
    public void batchRemoveDmsPullTeaDataDict( List<Long> ids ) throws Exception {


        if( !ObjectUtil.isNotEmptyList(ids) ){
            throw GlobalException.gen(10011, "要删除的id不存在");
        }
        dmsPullTeaDataDictMapper.deleteBatchIds(ids);
    }

}

      